import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/login.vue'
import Index from '../views/index.vue'
import News from '../views/news.vue'
import realtime from '../views/realtime.vue'
import publish from '../views/publish.vue'
import illustrate from '../views/illustrate.vue'
import edit from '../views/edit.vue'
import management from '../views/management.vue'
import commodityEdit from '../views/commodityEdit.vue'
import commodityEdit2 from '../views/commodityEdit2.vue'
import recharge from '../views/recharge.vue'
import interests from '../views/interests.vue'
import finance from '../views/finance.vue'
import financeInterests from '../views/financeInterests.vue'
import systemSettings from '../views/systemSettings.vue'
import noticeManage from '../views/noticeManage.vue'
import noticeManageEdit from '../views/noticeManageEdit.vue'
import administratorManage from '../views/administratorManage.vue'
import log from '../views/log.vue'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'login',
    component:Login
  },
  {
    path: '/index',
    component:Index,
    children:[
      {
        path: '/',
        component:realtime,
      },
      {
        path: 'publish',
        component:publish,
        // meta:{
        //     requireAuth:true
        //  }
      },
      {
        path: 'news',
        component:News,
        //  meta:{
        //      requireAuth:true
        //  }
      },
      //商品说明文档
      {
        path: 'illustrate',
        component:illustrate,
        //  meta:{
        //      requireAuth:true
        //  }
      },
      //编辑商品说明文档
      {
        path: 'edit',
        component:edit,
        //  meta:{
        //      requireAuth:true
        //  }
      },
      //全部商品管理
      {
        path: 'management',
        component:management,
      },
      //待上架商品编辑
      {
        path: 'commodityEdit',
        component:commodityEdit,
      },
      //下架商品编辑
      {
        path: 'commodityEdit2',
        component:commodityEdit2,
      },
      //用户充值记录
      {
        path: 'recharge',
        component:recharge,
        //  meta:{
        //      requireAuth:true
        //  }
      },
      //用户权益充值记录
      {
        path: 'interests',
        component:interests,
        //  meta:{
        //      requireAuth:true
        //  }
      },
      //充值对账单
      {
        path: 'finance',
        component:finance,
        //  meta:{
        //      requireAuth:true
        //  }
      },
      // 权益对账单
      {
        path: 'financeInterests',
        component:financeInterests,
        //  meta:{
        //      requireAuth:true
        //  }
      },
      // 管理员管理
      {
        path: 'administratorManage',
        component:administratorManage,
      },
      // 新增管理员
      {
        path: 'systemSettings',
        component:systemSettings,
      },
      // 通知管理
      {
        path: 'noticeManage',
        component:noticeManage,
      },
      // 编辑账户余额不足预警
      {
        path: 'noticeManageEdit',
        component:noticeManageEdit,
      },
      // 操作日志
      {
        path: 'log',
        component:log,
      },
    ],
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),
    meta:{
        requireAuth:true
    }
  }
]

const router = new VueRouter({
  routes,
  scrollBehavior (to, from, savedPosition) {
    return { x: 0, y: 0 }
  },
})

export default router
